﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PHPDecoder
{
    class BufferNode
    {
        public BufferNode next;
        public BufferNode prev;
        public char val;
        public BufferNode(char c)
        {
            next = null;
            prev = null;
        }
    }
    class RotBuffer
    {
        BufferNode root = null;
        public String s
        {
            get { return ToString(); }
        }

        public RotBuffer(int capacity)
        {
            BufferNode node = null;
            root = new BufferNode(' ');
            BufferNode prev = root;
            for (int i = 0; i < capacity - 1; i++)
            {
                node = new BufferNode(' ');
                node.prev = prev;
                prev.next = node;
                node = null;
                prev = prev.next;
            }
            prev.next = root;
            root.prev = prev;
            prev = null;
        }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            BufferNode n = root.prev;
            while (n != root)
            {
                sb.Append(n.val);
                n = n.prev;
            }
            return sb.ToString();
        }

        public void Add(char c)
        {
            root = root.prev;
            root.val = c;
        }
    }
}
